package com.ex.orage2app;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SearchView;


import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class IndexFragment extends Fragment implements View.OnClickListener {
    private SearchView searchViewLine;
    private LinearLayout qiuxieLine, paoxieLine, tuoxieLine,  xueziLine, banxieLine, gaogenxieLine;
    private GridView gridView;
    private List<Product> productList;
    private ProductAdapter productAdapter;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=LayoutInflater.from(getActivity()).inflate(R.layout.content_index,container,false);
        init(view);
        return view;
    }
    /**
     * 初始化组件
     */
    private void init(View view) {
        searchViewLine= view.findViewById(R.id.searchView);
        searchViewLine.setOnClickListener(this);
        qiuxieLine = view.findViewById(R.id.qiuxie);
        qiuxieLine.setOnClickListener(this);
        paoxieLine = view.findViewById(R.id.paoxie);
        paoxieLine.setOnClickListener(this);
        tuoxieLine = view.findViewById(R.id.tuoxie);
        tuoxieLine.setOnClickListener(this);
        xueziLine = view.findViewById(R.id.xuezi);
        xueziLine.setOnClickListener(this);
        gaogenxieLine = view.findViewById(R.id.banxie);
        gaogenxieLine.setOnClickListener(this);
        gaogenxieLine = view.findViewById(R.id.gaogenxie);
        gaogenxieLine.setOnClickListener(this);
        gridView = view.findViewById(R.id.index_famous_gridview);
        initData();
        productAdapter = new ProductAdapter(getActivity(), productList);
        gridView.setAdapter(productAdapter);
    }
    /**
     * 初始化商品数据
     */
    private void initData() {
        productList = new ArrayList<>();
        Product product = new Product();
        product.setImageUrlId(R.drawable.fanruowei);
        product.setProductName("梵诺威");
        product.setProductPrice(new BigDecimal("299.9"));
        Product product1 = new Product();
        product1.setImageUrlId(R.drawable.lilywei);
        product1.setProductName("Lily Wei");
        product1.setProductPrice(new BigDecimal("499.9"));
        Product product2 = new Product();
        product2.setImageUrlId(R.drawable.jimmy);
        product2.setProductName("Jimmy");
        product2.setProductPrice(new BigDecimal("2999.9"));
        Product product3 = new Product();
        product3.setImageUrlId(R.drawable.aj1);
        product3.setProductName("AJ1");
        product3.setProductPrice(new BigDecimal("899.9"));
        Product product4 = new Product();
        product4.setImageUrlId(R.drawable.simpsons);
        product4.setProductName("辛普森");
        product4.setProductPrice(new BigDecimal("199.9"));
        Product product5 = new Product();
        product5.setImageUrlId(R.drawable.dunk);
        product5.setProductName("Dunk");
        product5.setProductPrice(new BigDecimal("459.9"));
        productList.add(product);
        productList.add(product1);
        productList.add(product2);
        productList.add(product3);
        productList.add(product4);
        productList.add(product5);

    }

    @Override
    public void onClick(View view) {

    }
}
